package com.winchain.provider.expiration.cmd;

import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICommand;
import com.winchain.provider.expiration.po.CbDebit;
import com.winchain.provider.expiration.rx.BillExpirationEvent;
import com.winchain.provider.expiration.service.CbDebitService;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillExpDebitAssetCmd implements ICommand<BillExpirationEvent> {
	protected final Log logger = LogFactory.getLog(getClass());
	@Autowired
	private CbDebitService cbDebitService;

	public boolean execute(CommandContext<BillExpirationEvent> context) throws Exception {
		String expDate = ((BillExpirationEvent) context.getSource()).getDate();
		String grpId = ((BillExpirationEvent) context.getSource()).getGrpId();
		List<CbDebit> debits = getSuccessDebits(expDate, grpId);
		this.cbDebitService.resQuota(debits);
		return false;
	}

	private List<CbDebit> getSuccessDebits(String expDate, String grpId) {
		return this.cbDebitService.selectDebitBill(expDate, grpId, new String[] { "1" });
	}
}
